﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.CharacterDevelopment.CharacterAttributes
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System;
using System.Collections.Generic;
using System.Xml;
using TaleWorlds.Core;
using TaleWorlds.ObjectSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.CharacterDevelopment
{
  public class CharacterAttributes : PropertyOwner<CharacterAttribute>
  {
    internal static void AutoGeneratedStaticCollectObjectsCharacterAttributes(
      object o,
      List<object> collectedObjects)
    {
      ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    public CharacterAttributes()
    {
    }

    public CharacterAttributes(CharacterAttributes characterAttributes)
      : base((PropertyOwner<CharacterAttribute>) characterAttributes)
    {
    }

    public override void Deserialize(MBObjectManager objectManager, XmlNode node)
    {
      this.Initialize();
      foreach (XmlNode childNode in node.ChildNodes)
      {
        if (childNode.NodeType != XmlNodeType.Comment)
        {
          XmlAttributeCollection attributes = childNode.Attributes;
          string objectName = attributes["id"].Value;
          string str = attributes["value"].Value;
          CharacterAttribute attribute = Game.Current.ObjectManager.GetObject<CharacterAttribute>(objectName);
          if (attribute != null)
          {
            int int32 = str != null ? Convert.ToInt32(str) : 0;
            this.SetPropertyValue(attribute, int32);
          }
        }
      }
      foreach (XmlNode childNode in node.ChildNodes)
      {
        if (childNode.NodeType != XmlNodeType.Comment)
        {
          string objectName = childNode.Name;
          int num = 0;
          if (objectName == "characterAttribute")
          {
            objectName = (string) null;
            if (childNode.Attributes != null)
            {
              XmlAttribute attribute = childNode.Attributes["id"];
              if (attribute != null)
                objectName = attribute.InnerText;
            }
          }
          if (objectName != null)
          {
            CharacterAttribute attribute1 = Game.Current.ObjectManager.GetObject<CharacterAttribute>(objectName);
            if (attribute1 != null)
            {
              XmlAttribute attribute2 = childNode.Attributes["value"];
              if (attribute2 != null)
              {
                string str = attribute2.Value;
                num = str != null ? Convert.ToInt32(str) : 0;
              }
              this.SetPropertyValue(attribute1, num);
            }
          }
        }
      }
    }
  }
}
